/******FIGURE II: EFFECTS ON CIVIC ENGAGEMENT***********/

/*******RUN ANALYSIS**********/
use ../data/main.dta, clear
keep if sample_main==1
global fixed_effects "cb pop_dec#elec_id CBG#elec_id"

sum reg if tau==-1
local m = round(r(mean), .01)
	
eventdd reg all, timevar(tau)   ///
	absorb( $fixed_effects ) hdfe tolerance(0.0001) cluster(CBG) ///
	ci(rcap) ci_op(fcolor(gs10%30) lcolor(gs10))
	parmest, label saving (../estimates/fig2_reg, replace)
outreg2 using ../output/table_event.xls, append stats(coef se) ctitle(`y') dec(3) alpha(.01, .05, .10) addtext(killings, all, mean, `m') symbol(***, **, *) excel side

sum vote if tau==-1
local m = round(r(mean), .01)
	
eventdd vote all , timevar(tau) ///
	absorb( $fixed_effects ) hdfe cluster(CBG) ///
	ci(rcap) ci_op(fcolor(gs10%30) lcolor(gs10))
	parmest, label saving (../estimates/fig2_vote, replace)
outreg2 using ../output/table_event.xls, append stats(coef se) ctitle(`y') dec(3) alpha(.01, .05, .10) addtext(killings, all, mean, `m') symbol(***, **, *) excel side


/*******CREATE FIGURES*********/
local file = "fig2_reg"
use ../estimates/`file', clear

local lower = -8
local upper = 8
local lower1 = `lower'-.25
local upper1 = `upper'+.25
local increment = 2
local mcolor = "black"
local lcolor = "gs5"
local tsize = "large"
local labsize = "medlarge"

gen time = real(substr(parm, -1, 1))
replace time = time*-1 if strpos(parm, "lag")==0

drop if time==.

expand 2 if time==-2, gen(omit)
replace time = -1 if omit
replace estimate = 0 if omit
replace min95 = 0 if omit
replace max95 = 0 if omit

graph twoway (scatter estimate time, mcolor(`mcolor')) (rcap min95 max95 time, lcolor(`lcolor')), ///
	xline(-.5, lcolor(red)) yline(0, lcolor(gs5)) ///
	ylabel(`lower'(`increment')`upper', grid labsize(`labsize')) yscale(range(`lower1' `upper1')) ///
	xlabel(-4(1)3) xscale(range(-4 3)) ///
	ytitle("Registrations", size(`tsize')) ///
	xtitle("Elections to Killing", size(`tsize')) ///
	legend(off) plotregion(fcolor(white)) graphregion(fcolor(white) lwidth(large) lcolor(white)) bgcolor(white)
	graph export ../output/`file'.png, replace
	graph export ../output/`file'.eps, replace

local file = "fig2_vote"
use ../estimates/`file', clear

gen time = real(substr(parm, -1, 1))
replace time = time*-1 if strpos(parm, "lag")==0

drop if time==.

expand 2 if time==-2, gen(omit)
replace time = -1 if omit
replace estimate = 0 if omit
replace min95 = 0 if omit
replace max95 = 0 if omit

graph twoway (scatter estimate time, mcolor(`mcolor')) (rcap min95 max95 time, lcolor(`lcolor')), ///
	xline(-.5, lcolor(red)) yline(0, lcolor(gs5)) ///
	ylabel(`lower'(`increment')`upper', grid labsize(`labsize')) yscale(range(`lower1' `upper1')) ///
	xlabel(-4(1)3) xscale(range(-4 3)) ///
	ytitle("Votes", size(`tsize')) ///
	xtitle("Elections to Killing", size(`tsize')) ///
	legend(off) plotregion(fcolor(white)) graphregion(fcolor(white) lwidth(large) lcolor(white)) bgcolor(white)
	graph export ../output/`file'.png, replace
	graph export ../output/`file'.eps, replace
